<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Photos
 *
 * @author gliporace
 */
class Photos extends Record {
    //put your code here
    const TABLE_NAME = 'photos';
    public $id;
    public $photo_title;
    public $photo_filename;
    public $photo_caption;
    public $photo_category;
    public $visits;

    public function getId() {
        return $this->id;
    }

    public function getTitle() {
        return $this->photo_title;
    }

    public function getFilename() {
        return $this->photo_filename;
    }

    public function getCaption() {
        return $this->photo_caption;
    }

    public function getCategory() {
        return $this->photo_category;
    }

    public function getVisits() {
        return $this->visits;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function setTitle($title) {
        $this->photo_title = $title;
    }

    public function setFilename($filename) {
        $this->photo_filename = $filename;
    }

    public function setCaption($caption) {
        $this->photo_caption = $caption;
    }

    public function setCategory($category) {
        $this->photo_category = $category;
    }


    public function addVisitor() {
        (int)$this->visits += 1;
    }

    /**
     * Find a photo by its id
     *
     * @param int $id
     * @return array Return a Photos object
     */
    public function findById($id) {
        return Record::findByIdFrom('Photos', $id);
    }

    /**
     * Return a list of photo by categories
     *
     * @param int $category_id
     * @return array Return a list of Photos Objects
     */
    public function findAllByCategoryId($category_id) {
        return Record::findAllFrom('Photos', 'photo_category=:category_id', array(':category_id' => $category_id));
    }

    /**
     * Return the category into which a photo is loaded
     *
     * @param int $id
     * @return string Return the category name;
     */
     public function findCategoryByPhotoId($id) {
        return self::findById($id)->getCategory();
    }
}
?>
